package webadmin.config;

import webadmin.controller.AdminController;
import webadmin.controller.BlogrollController;
import webadmin.controller.UtilController;
import webadmin.model.Blogroll;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;

/**
 * User: Ulric Qin
 * Mail: ulric.qin@gmail.com
 */
public class GlobalConfig extends JFinalConfig {

    @Override
    public void configConstant(Constants constants) {
    	loadPropertyFile("config.properties");
		constants.setDevMode(getPropertyToBoolean("devMode", false));
		constants.setBaseViewPath("/WEB-INF/tpl");
    }

    @Override
    public void configRoute(Routes routes) {
        routes.add("/util", UtilController.class);
        routes.add("/admin", AdminController.class);
        routes.add("/admin/blogroll", BlogrollController.class);
    }

    @Override
    public void configPlugin(Plugins plugins) {
    	C3p0Plugin c3p0Plugin = new C3p0Plugin(
    			getProperty("jdbcUrl"), 
    			getProperty("jdbcUser"), 
    			getProperty("jdbcPass")
    			);
		plugins.add(c3p0Plugin);
		
		ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
		plugins.add(arp);
		arp.addMapping("blogroll", Blogroll.class);
    }

    @Override
    public void configInterceptor(Interceptors interceptors) {
    }

    @Override
    public void configHandler(Handlers handlers) {
    }
}
